package cn.zjutleo.village_server.controller;

import cn.zjutleo.village_server.annotation.RequestLimit;
import cn.zjutleo.village_server.annotation.RequiresLogin;
import cn.zjutleo.village_server.dto.UserUpdateDto;
import cn.zjutleo.village_server.service.UserService;
import cn.zjutleo.village_server.util.ThreadLocalUtil;
import cn.zjutleo.village_server.vo.ResponseBean;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : Qin Zhenghan
 * @date : Created in 2021/9/3
 * @description: 用户相关请求控制类
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 更新用户个人信息
     *
     * @param userUpdateDto 用户更新DTO
     */
    @RequestLimit(amount = 3)
    @RequiresLogin
    @PostMapping("/update/info")
    public ResponseBean<Object> updateUserInfo(@RequestBody @Validated UserUpdateDto userUpdateDto) {
        Integer userId = ThreadLocalUtil.getCurrentUser();
        userService.updateUserById(userUpdateDto, userId);
        return new ResponseBean<>(200, "用户个人信息更新成功", null);
    }
}
